<template>
  <div class="container">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="仓库名称">
        <el-input v-model="form.warehouseName"></el-input>
      </el-form-item>

      <el-form-item label="仓库备注">
        <el-input v-model="form.remark"></el-input>
      </el-form-item>

      <el-form-item label="是否启用">
        <el-switch v-model="form.status"></el-switch>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">确认添加</el-button>
        <el-button @click="canceAdd">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "addwarehouse",
  data(){
    return{
      form:{
        warehouseName:"",
        remark:'',
        status:false
      }
    }
  },
  methods:{
    onSubmit(){
      //校验数据合法性
      if (this.form.warehouseName==null||this.form.warehouseName.trim()==''){
        this.$message({
          message:"仓库名称不可以为空",
          type:'error'
        })
        return false;
      }
      if (this.form.remark==null||this.form.remark.trim()==''){
        this.$message({
          message:"备注不可以为空",
          type:'error'
        })
        return false;
      }
      this.form.status=this.form.status?0:1
      axios({
        url:'http://localhost:8080/api/warehouse/add',
        method:"post",
        data:this.form
      }).then(resp=>{
        if (resp.data.code==200){
          this.$message({
            message:resp.data.msg,
            type:"success"
          })
        }
        else this.$message({
          message:resp.data.msg,
          type:"error"
        })
        //关闭添加数据的对话框并刷新数据
        this.$bus.$emit("warehouse/closeAddWarehouseDialog",true)
      })
    },
    canceAdd(){
      this.$bus.$emit("warehouse/closeAddWarehouseDialog",false)

    }
  }
}
</script>

<style scoped>

</style>